import './index.scss';
import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js';
import Scroller from 'vux/src/components/scroller/index.vue'
import LoadMore from 'vux/src/components/load-more/index.vue'
import Tab from 'vux/src/components/tab/tab.vue'
import TabItem from 'vux/src/components/tab/tab-item.vue'
export default {
  name: 'userdonate',
  components: { Scroller, LoadMore, Tab, TabItem },
  data () {
    return {
      userId: '',
      witchShow: '1',
      use_pullup: true,
      pageNo: 1,
      pageNo2: 1,
      pageSize: 8,
      bounce: false,
      pullup_con: {
        content: ' ',
        pullUpHeight: 60,
        height: 40,
        autoRefresh: false,
        downContent: ' ',
        upContent: ' ',
        loadingContent: ' ',
        clsPrefix: 'xs-plugin-pullup-'
      },
      tipText: '上拉进行加载',
      show_loading: false,
      list: [],
      index: 0,
      index2: 1,
      listy: [],
      querys: '1'
    }
  },
  // watch: {
  //   witchShow: function (e) {
  //     if (e == '1') {
  //
  //     }
  //   }
  // },
  mounted () {
    document.body.scrollTop = document.documentElement.scrollTop = 0;
    this.userId = window.sessionStorage.getItem('userId')
    if (this.$emit('ifOpenid')) {
      this.$emit('ifOpenid', this.$route.path)
    }
    if (this.$route.query.showWitch == '1') {
      this.witchShow = '1'
      this.querys = '1'
    } else if (this.$route.query.showWitch == '2') {
      this.witchShow = '2'
      this.querys = '2'
    }
    this.tipText = '正在加载数据，请稍后'
    this.show_loading = true
    this.goEventList()
  },
  methods: {
    // 点击一起捐记录
    qiyijuanjilu () {
      this.witchShow = '2'
      if (this.listy.length < 1) {
        this.goEventList2()
      }
    },
    onScrollBottom () {
      // console.log('上拉加载')
      this.tipText = '正在加载数据，请稍后'
      this.show_loading = true
      this.pageNo++
      this.$nextTick(() => {
        this.$refs.scroller1.donePullup(function () {
        this.$refs.scroller1.reset()
      })
    })
      this.goEventList()
    },
    goEventList () {
      http.post(CONSTANT.PERSONDONATE, {userId: this.userId, pageNo: this.pageNo, pageSize: this.pageSize}, (res) => {
        console.log(res)
      if (this.pageNo == 1) {
        if (res.code == 200) {
          if (res.obj == '') {
            this.tipText = '暂时没有捐款记录'
            this.show_loading = false
            return
          }
          this.list = res.obj
          this.tipText = '上拉进行加载'
          this.show_loading = false
          this.$nextTick(() => {
            this.$refs.scroller1.donePullup(function () {
            this.$refs.scroller1.reset()
          })
        })
        } else {
          this.tipText = '加载数据失败'
          this.show_loading = false
        }
      } else {
        if (res.code == 200) {
          if (res.obj == '') {
            this.tipText = '没有更多捐赠记录了'
            this.show_loading = false
            return
          }
          this.list = this.list.concat(res.obj)
          this.tipText = '上拉进行加载'
          this.show_loading = false
          this.$nextTick(() => {
            this.$refs.scroller1.donePullup(function () {
            this.$refs.scroller1.reset()
          })
        })
        }
      }
    })
    },
    onScrollBottom2 () {
      // console.log('上拉加载')
      this.tipText = '正在加载数据，请稍后'
      this.show_loading = true
      this.pageNo2++
      this.goEventList2()
    },
    goEventList2 () {
      // 一起捐记录接口
      http.post(CONSTANT.TOGETHERDONATE, {userId: this.userId, pageNo: this.pageNo2, pageSize: this.pageSize}, (res) => {
        if (this.pageNo2 == 1) {
        if (res.code == 200) {
          if (res.obj == '') {
            this.tipText = '暂时没有捐款记录'
            this.show_loading = false
            return
          }
          this.listy = res.obj
          this.tipText = '上拉进行加载'
          this.show_loading = false

          this.$nextTick(() => {
            this.$refs.scroller.donePullup(function () {
            this.$refs.scroller.reset()
          })
        })
        }
      } else {
        if (res.code == 200) {
          if (res.obj == '') {
            this.tipText = '没有更多一起捐记录了'
            this.show_loading = false
            this.$nextTick(() => {
              this.$refs.scroller.donePullup(function () {
              this.$refs.scroller.reset()
            })
          })
            return
          }
          this.listy = this.listy.concat(res.obj)
          this.tipText = '上拉进行加载'
          this.show_loading = false
          this.$nextTick(() => {
            this.$refs.scroller.donePullup(function () {
            this.$refs.scroller.reset()
          })
        })
        }
      }
    })
    },
    goProject (id) {
      this.$router.push({path: '/Project', query: {'event_id': id}})
    },
    goHomeDoation (e) {
      this.$router.push({path: '/homedonation', query: {together_id: e}})
    },
    comeBack () {
      window.history.back()
    }
  }
}